<!DOCTYPE html>
<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>图像识别管理系统</title>
    <link href="../css/common.css" rel="stylesheet">
    <link rel="stylesheet" href="../css/layui.css" media="all">
    <link id="layuicss-layer" rel="stylesheet" href="../css/modules/layer/default/layer.css" media="all">
    <script src="../js/jquery-1.12.4.js"></script>
    <script type="text/javascript" src="../js/jstime/laydate.js"></script>
    <script type="text/javascript" src="../js/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../js/common.js" charset="utf-8"></script>
    <style>
        #wrapper {
            position: relative;
            display: flex;
        }

        #left,
        #right {
            width: 50%;
        }

        #line {
            position: absolute;
            left: calc(50% - 3px);
            width: 6px;
            height: calc(100% - 20px);
            margin: 10px 0;
            cursor: col-resize;
            background-color: #e2e2e2;
        }

        .searchBar input.laydate-icon {
            width: 100px;
        }

        #tableTwoTatol {
            height: 40px;
            line-height: 40px;
            font-size: 12px;
            padding-left: 16px;
            margin-top: -10px;
            /*border: 1px solid #e6e6e6;*/
            border-top: none;
        }
    </style>
</head>

<body>
<div class="searchBar">
    <label>关卡名称：</label><input id="codeName" />
    <label>关卡类型：</label><select style="width:100px;" id="codeGrade">
    <option value="">全部</option>
    <option value="0">基础</option>
    <option value="1">综合</option>
</select>
    <button id="search" data-type="check">查询</button>
</div>

<div id="wrapper">
    <!-- 左侧 -->
    <div id="left">
        <script type="text/html" id="toolbar">
            <button class="layui-btn layui-btn-sm" lay-event="refresh1">刷新</button>
            <button class="layui-btn layui-btn-sm" lay-event="add1">新增</button>
            <button class="layui-btn layui-btn-sm" lay-event="modify1">修改</button>
            <button class="layui-btn layui-btn-sm" lay-event="remove1">删除</button>
        </script>
        <div style="margin: 0 5px 0 10px;">
            <table id="tableOne" lay-filter="tableOne"></table>
        </div>
    </div>
    <!-- 右侧 -->
    <div id="right">
        <script type="text/html" id="toolbar2">
            <button class="layui-btn layui-btn-sm" lay-event="refresh2">刷新</button>
            <button class="layui-btn layui-btn-sm" lay-event="add2">新增</button>
            <button class="layui-btn layui-btn-sm" lay-event="modify2">修改</button>
            <button class="layui-btn layui-btn-sm" lay-event="remove2">删除</button>
        </script>
        <div style="margin: 0 10px 0 5px;">
            <table id="tableTwo" lay-filter="tableTwo"></table>
            <div id="tableTwoTatol"></div>
        </div>
    </div>
    <!-- 分隔条 -->
    <div id="line"></div>
</div>

</body>

</html>

<script type="text/javascript">
    layui.use(['table', "layer", "element", "laydate"], function () {
        var table = layui.table;
        var rateId;
        var toolbar = '#toolbar';
        var yesIndex = "";
        var sysLevel = "";
        var sH = layui.$(".searchBar").height();
        sH += 45;
        // sH = 'full-' + sH;

        var elemClass;

        var tableTwoCol = [
            { type: 'checkbox', fixed: 'left' },
             { field: 'levelId',  title: '关卡ID', sort: true ,width:80}
            , { field: 'levelCodeNum',  sort: true, title: '关卡编号',width:80 }
            , { field: 'levelCodeName',  sort: true, title: '关卡名称',width:110 }
            , { field: 'codeGrade',  sort: true, title: '关卡类型',width:110 }
            , { field: 'levelDifficulty',  title: '关卡难度', sort: true,width:110 }
            , { field: 'levelPuzzle',  title: '关卡谜题', sort: true,width:110 }
            , { field: 'levelTips',  title: '关卡提示', sort: true,width:110 }
            , { field: 'levelAnswer',  title: '关卡答案', sort: true ,width:110}
            , { field: 'levelAccuracy',  title: '关卡答案过关准线', sort: true,width:110 }
            , { field: 'levelExplain',  title: '关卡解释', sort: true,width:110 }
            , { field: 'levelScore',  title: '关卡分数', sort: true,width:110 }
            , { field: 'createdBy',  title: '创建人', sort: true,width:110 }
            , { field: 'createdTime',  title: '创建时间', sort: true ,width:160}
            , { field: 'updatedBy',  title: '更新人', sort: true ,width:110}
            , { field: 'updatedTime',  title: '更新时间', sort: true,width:160 }
        ]

        // 初始化表格1
        function initTableOne() {
            table.render({
                elem: '#tableOne'
                , toolbar: '#toolbar' // 开启头部工具栏，并为其绑定左侧模板
                , defaultToolbar: [{ title: '汇总', layEvent: 'collect1', icon: 'layui-icon-tips' },'filter', 'print']
                , height: 'full-' + sH
                , method: "post"
                , request: {
                    pageName: "page", // 页码的参数名称，默认：page
                    limitName: "rows" // 每页数据量的参数名，默认：limit
                }
                , limit: 50
                , limits: [50, 100, 500, 1000, 2000]
                /* 		,headers: { token: localStorage.getItem("token") }	 */
                , parseData: function (res) {//将回调函数解析成table所规定的数据格式
                    return {
                        msg: res.errMsg,
                        count: res.data ? res.data.total : 0,
                        data: res.data ? res.data.rows : [],
                        code: res.errCode
                    };
                }
                , url: webUrl + '/codeInfo/getPage' //数据接口
                , cols: [[
                    { type: 'checkbox', fixed: 'left' },
                     { field: 'codeId',  sort: true, title: 'ID值',width:80 }
                    , { field: 'codeNum',  sort: true, title: '关卡编号',width:110 }
                    , { field: 'codeName',  sort: true, title: '关卡名称',width:110 }
                    , { field: 'codeGrade',  sort: true, title: '关卡类型',width:110 }
                    , { field: 'createdBy',  sort: true, title: '创建人',width:100 }
                    , { field: 'createdTime',  sort: true, title: '创建时间',width:160 }
                    , { field: 'updatedBy',  sort: true, title: '更新人',width:100 }
                    , { field: 'updatedTime',  sort: true, title: '更新时间',width:160 }
                ]]
                , page: true
                , where: {
                    token: getCookie("token")
                },
                done: function (res) {
                    if (res.code == "000001") {
                        layer.confirm('登录信息已过期，请重新登录', {title: '系统提示', btn: ['确认']}, function (index) {
                            layer.close(index);
                            window.parent.returnLogin();
                        });
                    }

                    // 默认选中第一条 || 保存了当前正在查看的那条数据，存在就显示
                    if (res.data.length) {
                        var codeNum = res.data[0]['codeNum'];
                        CommentsServiceImpl = codeNum;
                        initTableTwo(codeNum);
                        var tr = $(".layui-table").find("tbody tr[data-index='0']");
                        tr.addClass("layui-table-click").siblings().removeClass("layui-table-click");
                    }else {
                        CommentsServiceImpl = "";
                        initTableTwo(CommentsServiceImpl);
                    }
                }
            })
            refreshTable(1, 'tableOne')
        }

        var num = 0;//全局变量,防止重复点击
        var codeNum = "";
        //监听行单击事件（双击事件为：rowDouble）
        table.on('row(tableOne)', function(obj) { //lay-filter="test"
            var selector = obj.tr.selector;//获取选中的data-index
            if (num != selector) {
                obj.tr.addClass("layui-table-click").siblings().removeClass("layui-table-click");
                num = selector;//必须放在前面,后续点击依然会触发该方法
                CommentsServiceImpl = obj.data.codeNum;
                initTableTwo(obj.data.codeNum);
            }

        });


        // 初始化表格2
        function initTableTwo(codeNum) {
            table.render({
                elem: '#tableTwo'
                , toolbar: '#toolbar2' //开启头部工具栏，并为其绑定左侧模板
                , defaultToolbar: [{ title: '汇总', layEvent: 'collect2', icon: 'layui-icon-tips' },'filter', 'print']
                , height: 'full-' + (sH + 41)
                , method: "post"
                , page: false
                , limit: Number.MAX_VALUE
                // , request: {
                //     pageName: "page", // 页码的参数名称，默认：page
                //     limitName: "rows" // 每页数据量的参数名，默认：limit
                // }
                // , limit: 50
                // , limits: [50, 100, 500, 1000, 2000]
                /* 		,headers: { token: localStorage.getItem("token") }	 */
                , parseData: function (res) {//将回调函数解析成table所规定的数据格式
                    return {
                        msg: res.errMsg,
                        // count: res.data.total,
                        data: res.data,
                        code: res.errCode
                    };
                }
                , url: webUrl + '/levelInfo/getLevelListByLevelCode' //数据接口
                , cols: [tableTwoCol]
                // , page: true
                , where: {
                    token: getCookie("token"),
                    levelCode: codeNum
                },
                done: function (res) {
                    if (res.code == "000001") {
                        layer.confirm('登录信息已过期，请重新登录', { title: '系统提示', btn: ['确认'] }, function (index) {
                            layer.close(index);
                            window.parent.returnLogin();
                        });
                    }
                    $("#tableTwoTatol").text("共 " + res.data.length + " 条")
                }
            })
        }
        initTableOne();
        // 表格1头部工具栏事件
        table.on('toolbar(tableOne)', function (obj) {
            var tableList1 = layui.table.cache["tableOne"];
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;
            switch (obj.event) {
                case 'refresh1':
                    elemClass = null;
                    refreshTable(1, 'tableOne')
                    break;
                case 'add1':
                    openAddLevel1();
                    break;
                case 'modify1':
                    openModifyLevel1(data);
                    break;
                case 'remove1':
                    elemClass = null;
                    openDeleteLevel1(data)
                    break;
                case 'collect1':
                    layer.alert("当前页面数据汇总<br/>关卡总数："+tableList1.length
                        +" 个");
                    break;
            }
        })
//打开添加信息弹窗
        function openAddLevel1() {
            layer.open({
                type: 1,
                title: "添加订单",
                area: "600px",
                shade: 0.5,
                btn: ["确认", "取消"],
                offset: '100px',
                btnAlign: "c",
                moveType: 1,
                content:
                    '<div class="popupCont">' +
                    '<label  class="w60" ><b class="mustLabel">*</b>关卡名称:</label>' +
                    '<input id="newCodeName" autocomplete="off"  style="width:150px"/>' +
                    '<label  class="w60"><b class="mustLabel">*</b>关卡类型:</label><select style="width:100px;" id="newCodeGrade">' +
                    '    <option value="0">基础</option>' +
                    '    <option value="1">综合</option>' +
                    '</select>' +
                    '</div>' +
                    '<div class="popupCont">' +
                    '<label  class="w60" ><b class="mustLabel">*</b>关卡编号:</label>' +
                    '<input id="newCodeNum" autocomplete="off"  style="width:150px"/>' +
                    '</div>'
                , success: function () {
                }
                , yes:(index)=>{
                    confirmInfoMsg1("add");
                    yesIndex = index;
                },
            });
        }

        //打开修信息弹窗
        function openModifyLevel1(data) {
            /* 		console.log(data); */
            layer.open({
                type: 1,
                title: "修改信息",
                area: "600px",
                shade: 0.5,
                btn: ["确认", "取消"],
                offset: '100px',
                btnAlign: "c",
                moveType: 1,
                content:
                    '<div class="popupCont">' +
                    '<label  class="w60" ><b class="mustLabel">*</b>关卡名称:</label>' +
                    '<input id="newCodeName" autocomplete="off"  style="width:150px"/>' +
                    '<label  class="w60"><b class="mustLabel">*</b>关卡类型:</label><select style="width:100px;" id="newCodeGrade">' +
                    '    <option value="0">基础</option>' +
                    '    <option value="1">综合</option>' +
                    '</select>' +
                    '</div>' +
                    '<div class="popupCont">' +
                    '<label  class="w60" ><b class="mustLabel">*</b>关卡编号:</label>' +
                    '<input id="newCodeNum" autocomplete="off"  style="width:150px"/>' +
                    '<input readonly autocomplete="off" type="hidden" id="newCodeId" />' +
                    '</div>'
                , success: function () {
                    data = data[0];
                    $("#newCodeId").val(data.codeId);
                    $("#newCodeName").val(data.codeName);
                    $("#newCodeGrade").val(data.codeGrade);
                    $("#newCodeNum").val(data.codeNum);
                }
                , yes:(index)=>{
                    confirmInfoMsg1("modify");
                    yesIndex = index;
                },
            });
        }

        //校验输入信息
        function confirmInfoMsg1(flag) {
            if (flag == "modify") {
                var newCodeId = $("#newCodeId").val();
            }

            var newCodeName = $("#newCodeName").val();
            var newCodeGrade = $("#newCodeGrade").val();
            var newCodeNum = $("#newCodeNum").val();

            /* newOrderNum = $.trim(newOrderNum); */
            newCodeName = $.trim(newCodeName);
            console.log("newCodeName:"+newCodeName+" newCodeGrade:"+newCodeGrade);
            if(flag === "add") {
                if (newCodeName === "") {
                    layer.msg("关卡名称不能为空");
                    return;
                }
                if (newCodeNum === "") {
                    layer.msg("关卡编号不能为空");
                    return;
                }
            }
            if (flag == "add") {
                var data = {
                    /* type:newType, */
                    codeName: newCodeName,
                    codeGrade: newCodeGrade,
                    codeNum: newCodeNum,
                };
                //添加的操作
                requestAdd1(data);
            } else {
                //修改的操作
                var data = {
                    codeId: newCodeId,
                    /* type:newType, */
                    codeName: newCodeName,
                    codeGrade: newCodeGrade,
                    codeNum: newCodeNum,
                };
                requestModify1(data);
            }
        }

        //添加订单的请求
        function requestAdd1(data) {
            AddLoad = layer.load(2, { shade: 0.1 })
            sendPostAjax(
                webUrl + "/codeInfo/save",
                data,
                AddOrderCallBack1
            );
        }

        //添加订单的回调
        function AddOrderCallBack1(data) {
            layer.close(AddLoad);
            /* console.log(data); */
            if (data == null) {
                return;
            }
            if (data.errCode == "000001") {
                layer.confirm('登录信息已过期，请重新登录', { title: '系统提示', btn: ['确认'] }, function (index) {
                    layer.close(index);
                    window.parent.returnLogin();
                });
                return;
            }
            if (data.errCode == "000000") {
                layer.close(yesIndex);
                layer.msg(data.errMsg);
            } else {
                layer.alert(data.errMsg);
                return;
            }
            refreshTable(1, 'tableOne');
        }


        //修改订单的请求
        function requestModify1(data) {
            /* 	console.log(data); */
            ModifyLoad = layer.load(2, { shade: 0.1 })
            sendPostAjax(
                webUrl + "/codeInfo/modify",
                data,
                ModifyOrderCallBack1
            );
        }

        //修改订单的回调
        function ModifyOrderCallBack1(data) {
            layer.close(ModifyLoad);
            /* console.log(data); */
            if (data == null) {
                return;
            }
            if (data.errCode == "000001") {
                layer.confirm('登录信息已过期，请重新登录', { title: '系统提示', btn: ['确认'] }, function (index) {
                    layer.close(yesIndex);
                    window.parent.returnLogin();
                });
                return;
            }
            if (data.errCode == "000000") {
                layer.close(yesIndex);
                layer.msg(data.errMsg);
            } else {
                layer.alert(data.errMsg);
                return;
            }
            refreshTable(1, 'tableOne');
        }
        //删除订单确认
        function openDeleteLevel1(data) {
            layer.confirm('当前选中的关卡删除后将无法恢复，确认要删除吗', { title: '系统提示', btn: ['确认', '取消'] }, function (index) {
                layer.close(index);
                deleteLevel1(data);
            });
        }
        //删除订单请求
        function deleteLevel1(data) {
            var idList = '';
            for (var i = 0; i < data.length; i++) {
                if (i == data.length - 1) {
                    idList += data[i].codeId;
                } else {
                    idList += data[i].codeId + ",";
                }
            }
            var data = {
                idList: idList
            }
            DeleteLoad = layer.load(2, { shade: 0.1 })
            sendPostAjax(
                webUrl + "/codeInfo/remove",
                data,
                deleteOrderCallBack1
            );
        }
        //删除订单回调
        function deleteOrderCallBack1(data) {
            layer.close(DeleteLoad);
            /* console.log(data); */
            if (data == null) {
                return;
            }
            if (data.errCode == "000001") {
                layer.confirm('登录信息已过期，请重新登录', { title: '系统提示', btn: ['确认'] }, function (index) {
                    layer.close(index);
                    window.parent.returnLogin();
                });
                return;
            }
            if (data.errCode == "000000") {
                layer.msg(data.errMsg);
            } else {
                layer.alert(data.errMsg);
                return;
            }
            refreshTable(1, 'tableOne');
        }

        // 表格2头部工具栏事件
        table.on('toolbar(tableTwo)', function (obj) {
            var tableList2 = layui.table.cache["tableTwo"];
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;
            switch (obj.event) {
                case 'refresh2':
                    refreshTable(1, 'tableTwo')
                    break;
                case 'add2':
                    openAddLevel();
                    break;
                case 'modify2':
                    openModifyLevel(data);
                    break;
                case 'remove2':
                    deleteLevel(data);
                    break;
                case 'collect2':
                    layer.alert("当前页面数据汇总<br/>关卡总数："+tableList2.length
                        +" 个");
                    break;
            }
        })


        //打开添加信息弹窗
        function openAddLevel() {
            layer.open({
                type: 1,
                title: "添加信息",
                area: "600px",
                shade: 0.5,
                btn: ["确认", "取消"],
                offset: '100px',
                btnAlign: "c",
                moveType: 1,
                content:
                    '<div class="popupCont">' +
                    '<label  style="display: none" class="w60" ><b class="mustLabel">*</b>关卡编号:</label>' +
                    '<input  style="display: none" readonly id="codeName" autocomplete="off"  style="width:150px"/>' +
                    '<label  class="w60"><b class="mustLabel">*</b>关卡难度:</label><select style="width:100px;" id="levelDifficulty">' +
                    '    <option value="0">小白</option>' +
                    '    <option value="1">入门</option>' +
                    '    <option value="2">大师</option>' +
                    '</select>' +
                    '</div>' +
                    '<div class="popupCont">' +
                    '<label  class="w60" style="position: absolute; margin-top: -20px;"><b class="mustLabel">*</b>关卡谜题:</label><textarea id="levelPuzzle" autocomplete="off"  style="width:180px;height: 150px;margin-left: 80px;"/>' +
                    '<label  class="w60" style="position: absolute; margin-top: -20px;"><b class="mustLabel">*</b>关卡提示:</label><textarea id="levelTips" autocomplete="off"  style="width:180px;height: 150px;margin-left: 80px;"/>' +
                    '</div>' +
                    '<div class="popupCont">' +
                    '<label  class="w60" style="position: absolute; margin-top: -20px;"><b class="mustLabel">*</b>关卡答案:</label><textarea id="levelAnswer" autocomplete="off"  style="width:180px;height: 150px;margin-left: 80px;"/>' +
                    '<label  class="w60" style="position: absolute; margin-top: -20px;"><b class="mustLabel">*</b>关卡解释:</label><textarea id="levelExplain" autocomplete="off"  style="width:180px;height: 150px;margin-left: 80px;" />' +
                    '</div>' +
                    '<div class="popupCont">' +
                    '<label  class="w60"><b class="mustLabel">*</b>关卡分数:</label><input id="levelScore" autocomplete="off"  style="width:150px"/>' +
                    '<label  class="w60"><b class="mustLabel">*</b>过关准线:</label><select style="width:100px;" id="levelAccuracy">' +
                    '    <option value="1.00">100%</option>' +
                    '    <option value="0.90">90%</option>' +
                    '    <option value="0.80">80%</option>' +
                    '    <option value="0.70">70%</option>' +
                    '    <option value="0.60">60%</option>' +
                    '</select>' +
                    '</div>' +
                    '<div class="popupCont">' +
                    '<input readonly autocomplete="off" type="hidden" id="levelCode" />' +
                    '</div>'
                , success: function () {
                }
                , yes:(index)=>{
                    confirmInfoMsg("add");
                    yesIndex = index;
                },
            });
        }

        //打开修信息弹窗
        function openModifyLevel(data) {
            /* 		console.log(data); */
            layer.open({
                type: 1,
                title: "修改信息",
                area: "600px",
                shade: 0.5,
                btn: ["确认", "取消"],
                offset: '100px',
                btnAlign: "c",
                moveType: 1,
                content:
                    '<div class="popupCont">' +
                    '<label style="display: none"  class="w60"><b class="mustLabel">*</b>关卡编号:</label>' +
                    '<input style="display: none"  readonly id="codeName" autocomplete="off"  style="width:150px"/>' +
                    '<label  class="w60"><b class="mustLabel">*</b>关卡难度:</label><select style="width:100px;" id="levelDifficulty">' +
                    '    <option value="0">小白</option>' +
                    '    <option value="1">入门</option>' +
                    '    <option value="2">大师</option>' +
                    '</select>' +
                    '</div>' +
                    '<div class="popupCont">' +
                    '<label  class="w60" style="position: absolute; margin-top: -20px;"><b class="mustLabel">*</b>关卡谜题:</label><textarea id="levelPuzzle" autocomplete="off"  style="width:180px;height: 150px;margin-left: 80px;"/>' +
                    '<label  class="w60" style="position: absolute; margin-top: -20px;"><b class="mustLabel">*</b>关卡提示:</label><textarea id="levelTips" autocomplete="off"  style="width:180px;height: 150px;margin-left: 80px;"/>' +
                    '</div>' +
                    '<div class="popupCont">' +
                    '<label  class="w60" style="position: absolute; margin-top: -20px;"><b class="mustLabel">*</b>关卡答案:</label><textarea id="levelAnswer" autocomplete="off"  style="width:180px;height: 150px;margin-left: 80px;"/>' +
                    '<label  class="w60" style="position: absolute; margin-top: -20px;"><b class="mustLabel">*</b>关卡解释:</label><textarea id="levelExplain" autocomplete="off"  style="width:180px;height: 150px;margin-left: 80px;" />' +
                    '</div>' +
                    '<div class="popupCont">' +
                    '<label  class="w60"><b class="mustLabel">*</b>关卡分数:</label><input id="levelScore" autocomplete="off"  style="width:150px"/>' +
                    '<label  class="w60"><b class="mustLabel">*</b>过关准线:</label><select style="width:100px;" id="levelAccuracy">' +
                    '    <option value="1.00">100%</option>' +
                    '    <option value="0.90">90%</option>' +
                    '    <option value="0.80">80%</option>' +
                    '    <option value="0.70">70%</option>' +
                    '    <option value="0.60">60%</option>' +
                    '</select>' +
                    '</div>' +
                    '<div class="popupCont">' +
                    '<input type="hidden" id="levelCode" /></div>' +
                    '<div class="popupCont"><input type="hidden" id="levelId" />' +
                    '</div>'
                , success: function () {
                    data = data[0];
                    $("#levelId").val(data.levelId);
                    $("#levelDifficulty").val(data.levelDifficulty);
                    $("#levelPuzzle").val(data.levelPuzzle);
                    $("#levelTips").val(data.levelTips);
                    $("#levelAnswer").val(data.levelAnswer);
                    $("#levelAccuracy").val(data.levelAccuracy);
                    $("#levelExplain").val(data.levelExplain);
                    $("#levelScore").val(data.levelScore);
                }
                , yes:(index)=>{
                    confirmInfoMsg("modify");
                    yesIndex = index;
                },
            });
        }

        //校验输入信息
        function confirmInfoMsg(flag) {
            if (flag == "modify") {
                var levelId = $("#levelId").val();
            }

            var levelDifficulty = $("#levelDifficulty").val();
            var levelPuzzle = $("#levelPuzzle").val();
            var levelTips = $("#levelTips").val();
            var levelAnswer = $("#levelAnswer").val();
            var levelExplain = $("#levelExplain").val();
            var levelScore = $("#levelScore").val();
            var levelAccuracy = $("#levelAccuracy").val();
            console.log(" levelDifficulty:"+levelDifficulty+
                " levelScore:"+levelScore+"levelAccuracy:"+levelAccuracy);
            /* newOrderNum = $.trim(newOrderNum); */
            levelPuzzle = $.trim(levelPuzzle);
            levelTips = $.trim(levelTips);
            levelAnswer = $.trim(levelAnswer);
            levelAccuracy = $.trim(levelAccuracy);
            levelExplain = $.trim(levelExplain);
            levelScore = $.trim(levelScore);
            if(flag === "add") {
                if (CommentsServiceImpl === "") {
                    layer.msg("关卡编号不能为空");
                    return;
                }
                if (levelDifficulty === "") {
                    layer.msg("关卡难度不能为空");
                    return;
                }
                if (levelAccuracy === "") {
                    layer.msg("过关准线不能为空");
                    return;
                }

            }
            if (levelPuzzle === "") {
                layer.msg("关卡谜题不能为空");
                return;
            }
            if (levelTips === "") {
                layer.msg("关卡提示不能为空");
                return;
            }
            if (levelAnswer === "") {
                layer.msg("关卡答案不能为空");
                return;
            }
            if (levelExplain === "") {
                layer.msg("关卡解释不能为空");
                return;
            }

            if (!(/(^[1-9]\d*$)/.test(levelScore)) || levelScore <= 0) {
                layer.msg("分数必须为大于0的正整数");
                return;
            }
            if (flag == "add") {
                var data = {
                    /* type:newType, */
                    levelCode: CommentsServiceImpl,
                    levelDifficulty: levelDifficulty,
                    levelPuzzle: levelPuzzle,
                    levelTips: levelTips,
                    levelExplain: levelExplain,
                    levelAnswer: levelAnswer,
                    levelAccuracy: levelAccuracy,
                    levelScore: levelScore,
                };
                //添加的操作
                requestAdd(data);
            } else {
                //修改的操作
                var data = {
                    levelId: levelId,
                    /* type:newType, */
                    levelCode: CommentsServiceImpl,
                    levelDifficulty: levelDifficulty,
                    levelPuzzle: levelPuzzle,
                    levelTips: levelTips,
                    levelExplain: levelExplain,
                    levelAnswer: levelAnswer,
                    levelAccuracy: levelAccuracy,
                    levelScore: levelScore,
                };
                requestModify(data);
            }
        }

        //添加订单的请求
        function requestAdd(data) {
            AddLoad = layer.load(2, { shade: 0.1 })
            sendPostAjax(
                webUrl + "/levelInfo/addSysInfo",
                data,
                AddOrderCallBack
            );
        }

        //添加订单的回调
        function AddOrderCallBack(data) {
            layer.close(AddLoad);
            /* console.log(data); */
            if (data == null) {
                return;
            }
            if (data.errCode == "000001") {
                layer.confirm('登录信息已过期，请重新登录', { title: '系统提示', btn: ['确认'] }, function (index) {
                    layer.close(index);
                    window.parent.returnLogin();
                });
                return;
            }
            if (data.errCode == "000000") {
                layer.close(yesIndex);
                layer.msg(data.errMsg);
            } else {
                layer.alert(data.errMsg);
                return;
            }
            refreshTable(1, 'tableTwo');
        }


        //修改订单的请求
        function requestModify(data) {
            /* 	console.log(data); */
            ModifyLoad = layer.load(2, { shade: 0.1 })
            sendPostAjax(
                webUrl + "/levelInfo/modifySysInfo",
                data,
                ModifyOrderCallBack
            );
        }

        //修改订单的回调
        function ModifyOrderCallBack(data) {
            layer.close(ModifyLoad);
            /* console.log(data); */
            if (data == null) {
                return;
            }
            if (data.errCode == "000001") {
                layer.confirm('登录信息已过期，请重新登录', { title: '系统提示', btn: ['确认'] }, function (index) {
                    layer.close(yesIndex);
                    window.parent.returnLogin();
                });
                return;
            }
            if (data.errCode == "000000") {
                layer.close(yesIndex);
                layer.msg(data.errMsg);
            } else {
                layer.alert(data.errMsg);
                return;
            }
            refreshTable(1, 'tableTwo');
        }
        //删除订单确认
        function openDeleteLevel(data) {
            layer.confirm('当前选中的关卡删除后将无法恢复，确认要删除吗', { title: '系统提示', btn: ['确认', '取消'] }, function (index) {
                layer.close(index);
                deleteLevel(data);
            });
        }
        //删除订单请求
        function deleteLevel(data) {
            var idList = '';
            for (var i = 0; i < data.length; i++) {
                if (i == data.length - 1) {
                    idList += data[i].levelId;
                } else {
                    idList += data[i].levelId + ",";
                }
            }
            var data = {
                idList: idList
            }
            DeleteLoad = layer.load(2, { shade: 0.1 })
            sendPostAjax(
                webUrl + "/levelInfo/remove",
                data,
                deleteOrderCallBack
            );
        }
        //删除订单回调
        function deleteOrderCallBack(data) {
            layer.close(DeleteLoad);
            /* console.log(data); */
            if (data == null) {
                return;
            }
            if (data.errCode == "000001") {
                layer.confirm('登录信息已过期，请重新登录', { title: '系统提示', btn: ['确认'] }, function (index) {
                    layer.close(index);
                    window.parent.returnLogin();
                });
                return;
            }
            if (data.errCode == "000000") {
                layer.msg(data.errMsg);
            } else {
                layer.alert(data.errMsg);
                return;
            }
            refreshTable(1, 'tableTwo');
        }

        // 表格1/2刷新事件 ---- 执行重载
        function refreshTable(page, type) {
            switch (type) {
                case 'tableOne':
                    table.reload(type, {
                        page: {
                            curr: page
                        }
                        , where: {
                            deliverDateStartMin: $("#deliverDateStartMin").val(),
                            deliverDateStartMax: $("#deliverDateStartMax").val()
                        }
                    })
                    break;
                case 'tableTwo':
                    initTableTwo(CommentsServiceImpl);
                    break;
            }
        }

        $('#search').on('click', function () {
            search(1);
        });

        //搜索
        function search(page) {
            //执行重载
            var query = page ? { page: { curr: page } } : {}
            query['where'] = {
                codeName: layui.$("#codeName").val(),
                codeGrade: layui.$("#codeGrade").val(),
            }
            table.reload('tableOne', query);

        }

        function resizeTableWidth() {
            var line = $("#line")
            var clientX, moveX, oldLeftWidth, oldRightWidth, oldlineLeft;
            // 鼠标按下
            line.on("mousedown", function (ev) {
                oldLeftWidth = parseInt($("#left").css("width"))
                oldRightWidth = parseInt($("#right").css("width"))
                oldlineLeft = parseInt($("#line").css("left"))
                var ev = ev || event;
                clientX = ev.clientX;
                var body = document.body;
                $("body").css("user-select", "none")

                body.addEventListener("mousemove", function (ev) {
                    var ev = ev || event;
                    moveX = ev.clientX;
                    if (clientX && oldLeftWidth + (moveX - clientX) > 356 && oldRightWidth - (moveX - clientX) > 320) {
                        line.css("left", oldLeftWidth + (moveX - clientX) - 3)
                        $("#left").css("width", oldLeftWidth + (moveX - clientX))
                        $("#right").css("width", oldRightWidth - (moveX - clientX))
                        table.resize('tableOne');
                        table.resize('tableTwo');
                    }
                })

                body.addEventListener("mouseup", function () {
                    clientX = null;
                    body.onmousemove = null;
                    body.onmouseup = null;
                    $("body").css("user-select", "auto")
                })
            })
        }
        resizeTableWidth()
    })

</script>